package com.gexiaobao.pigeon.ui.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.view.isVisible
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.MemberReservationResponse

/**
 * @Author      : hxw
 * @Date        : 2024/6/7 17:07
 * @Describe    :
 */
class RxDialogModifyAppointmentInfo(context: Context?) : RxDialog(context!!) {

    private lateinit var cancelView: AppCompatTextView
    private lateinit var sureView: AppCompatTextView
    private lateinit var etDialogMakeAnAppointmentName: AppCompatEditText
    private lateinit var etDialogMakeAnAppointmentMobile: AppCompatEditText
    private lateinit var tvDialogMakeAnAppointmentArea: AppCompatTextView
    private lateinit var etDialogMakeAnAppointmentAddressDetail: AppCompatEditText
    private lateinit var etDialogMakeAnAppointmentRealName: AppCompatEditText
    private lateinit var etDialogMakeAnAppointmentNo: AppCompatEditText
    private lateinit var llDialogRealNameInfo: LinearLayout
    private lateinit var ivMakeAnAppointmentArea: AppCompatImageView

    init {
        initView()
    }

    @SuppressLint("MissingInflatedId")
    private fun initView() {
        val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_modify_appointment_info, null)
        cancelView = dialogView.findViewById(R.id.tvDialogCancel)
        sureView = dialogView.findViewById(R.id.tvDialogSure)
        etDialogMakeAnAppointmentName = dialogView.findViewById(R.id.etDialogMakeAnAppointmentName)
        etDialogMakeAnAppointmentMobile = dialogView.findViewById(R.id.etDialogMakeAnAppointmentMobile)
        tvDialogMakeAnAppointmentArea = dialogView.findViewById(R.id.tvDialogMakeAnAppointmentArea)
        etDialogMakeAnAppointmentAddressDetail = dialogView.findViewById(R.id.etDialogMakeAnAppointmentAddressDetail)
        etDialogMakeAnAppointmentRealName = dialogView.findViewById(R.id.etDialogMakeAnAppointmentRealName)
        etDialogMakeAnAppointmentNo = dialogView.findViewById(R.id.etDialogMakeAnAppointmentNo)
        llDialogRealNameInfo = dialogView.findViewById(R.id.llDialogRealNameInfo)
        ivMakeAnAppointmentArea = dialogView.findViewById(R.id.ivMakeAnAppointmentArea)

        cancelView.setOnClickListener {
            dismiss()
        }
        setContentView(dialogView)
    }

    fun setChooseAddress(listener: View.OnClickListener?) {
        tvDialogMakeAnAppointmentArea.setOnClickListener(listener)
        ivMakeAnAppointmentArea.setOnClickListener(listener)
    }

    fun setSureListener(listener: View.OnClickListener?) {
        sureView.setOnClickListener(listener)
    }

    fun setCancelListener(listener: View.OnClickListener?) {
        cancelView.setOnClickListener(listener)
    }

    fun getMemberName(): String {
        return etDialogMakeAnAppointmentName.text.toString().trim()
    }

    fun getMobile(): String {
        return etDialogMakeAnAppointmentMobile.text.toString().trim()
    }

    fun geRaceArea(): String {
        return tvDialogMakeAnAppointmentArea.text.toString().trim()
    }

    fun getRealName(): String {
        return etDialogMakeAnAppointmentRealName.text.toString().trim()
    }

    fun getIDCardNum(): String {
        return etDialogMakeAnAppointmentNo.text.toString().trim()
    }

    fun getAddressDetail(): String {
        return etDialogMakeAnAppointmentAddressDetail.text.toString().trim()
    }

    fun setAddressArea(area: String) {
        tvDialogMakeAnAppointmentArea.text = area
    }

    fun setHideRealInfo(isHide: Boolean) {
        llDialogRealNameInfo.isVisible = isHide
    }

    fun setAppointmentInfo(memberInfo: MemberReservationResponse) {
        etDialogMakeAnAppointmentName.setText(memberInfo.name)
        etDialogMakeAnAppointmentMobile.setText(memberInfo.mobile)
        tvDialogMakeAnAppointmentArea.text = memberInfo.address
        etDialogMakeAnAppointmentAddressDetail.setText(memberInfo.detailAddr)
        etDialogMakeAnAppointmentNo.setText(memberInfo.IDCard)
        etDialogMakeAnAppointmentRealName.setText(memberInfo.realName)
    }
}